<?php
if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
	die ( 'ACCESS DENIED. Don\'t load this page directly. Thanks.' );

if ( !empty($post->post_password) ) :
	if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :
		__( '<p><span class="req">Password required</span></p>', 'mim' );
		return;
	endif;
endif;

if ( $comments ) :
	global $mim_comment_alt;
	$trackback_count = $comment_count = 0;

	foreach ( $comments as $comment )
		get_comment_type() == 'comment' ? ++$comment_count : ++$trackback_count;

	if ( $comment_count ) : ?>

	<h3 id="comments"><?php printf( $comment_count > 1 ? __( 'Comments (%d)', 'mim' ) : __( 'Comments (1)', 'sandbox' ), $comment_count ) ?></h3>
<?php foreach ( $comments as $comment ) : if ( get_comment_type() == 'comment' ) : ?>
	<div id="comment-<?php comment_ID() ?>">
		<div class="ct"><?php printf( __( '%1$s&#160;<span class="cm">%2$s at %3$s</span>', 'mim' ),
			get_mim_commenter(),
			get_comment_date(),
			get_comment_time() );
			edit_comment_link( __( 'Edit', 'mim' ), '&#160;<span class="cm">', '</span>' );
			if ( $comment->comment_approved == '0' ) _e( '<br /><em>Awaiting moderation</em>', 'mim' ); ?></div>
<?php comment_text() ?>
	</div>
<?php endif; endforeach; endif; if ( $trackback_count ) : ?>
	<h3 id="trackbacks"><?php printf( $trackback_count > 1 ? __( 'Trackbacks (%d)', 'mim' ) : __( 'Trackbacks (1)', 'mim' ), $trackback_count ) ?></h3>
<?php foreach ( $comments as $comment ) : if ( get_comment_type() != 'comment' ) : ?>
	<div id="comment-<?php comment_ID() ?>">
		<div class="ct"><?php printf( __( '%1$s&#160;<span class="cm">%2$s at %3$s</span>', 'mim' ),
			get_mim_trackbacker(),
			get_comment_date(),
			get_comment_time() );
			edit_comment_link( __( 'Edit', 'mim' ), '&#160;<span class="cm">', '</span>' );
			if ( $comment->comment_approved == '0' ) _e( '<br /><em>Awaiting moderation</em>', 'mim' ); ?></div>
	</div>
<?php endif; endforeach; endif; endif; if ( 'open' == $post->comment_status ) : $required = get_option('require_name_email'); ?>

	<h3 id="respond"><?php _e( 'Post a comment', 'mim' ) ?></h3>
<?php if ( get_option('comment_registration') && !$user_ID ) :
		printf( __( "\t" . '<p>You must be <a href="%s" title="Log in">logged in</a> to post a comment.</p>' . "\n", 'mim' ), get_bloginfo('wpurl') . '/wp-login.php?redirect_to=' . get_permalink() );
else : ?>
	<form title="<?php _e( 'Post a comment', 'mim' ) ?>" method="post" action="<?php bloginfo('url') ?>/wp-comments-post.php">
<?php if ( $user_ID ) : ?>
		<p><?php printf(__('Logged in as <a href="%1$s" title="Logged in profile">%2$s</a>. <a href="%3$s" title="Log out">Log out?</a>', 'mim' ),
			get_bloginfo('wpurl') . '/wp-admin/profile.php',
			wp_specialchars( $user_identity, true ),
			get_bloginfo('wpurl') . '/wp-login.php?action=logout&amp;redirect_to=' . get_permalink() ) ?></p>
<?php else : if ( $required ) _e("\t\t" . '<p><span class="req">*</span>Required field</p>' . "\n", 'mim' ); ?>
		<p><label for="author"><?php _e( 'Name', 'mim' ); if ( $required ) _e('<span class="req">*</span>', 'mim') ?></label><br /><input id="author" name="author" type="text" class="text" value="<?php echo $comment_author ?>" size="20" maxlength="20" accesskey="1" <?php if ( get_option('mim_mobile_xhtml') == 3 ) echo 'inputmode="latin titleCase" '; ?>/></p>
		<p><label for="email"><?php _e( 'Email', 'mim' ); if ( $required ) _e('<span class="req">*</span>', 'mim') ?></label><br /><input id="email" name="email" type="text" class="text" value="<?php echo $comment_author_email ?>" size="20" maxlength="50" accesskey="2" <?php if ( get_option('mim_mobile_xhtml') == 3 ) echo 'inputmode="latin lowerCase" '; ?>/></p>
		<p><label for="url"><?php _e( 'Website', 'mim' ) ?></label><br /><input id="url" name="url" type="text" class="text" value="<?php echo $comment_author_url ?>" size="20" maxlength="50" accesskey="3" <?php if ( get_option('mim_mobile_xhtml') == 3 ) echo 'inputmode="latin lowerCase" '; ?>/></p>
<?php endif; ?>
		<p><label for="comment"><?php _e( 'Comment', 'mim' ); if ( $required ) _e('<span class="req">*</span>', 'mim') ?></label><br /><textarea id="comment" name="comment" class="text" cols="30" rows="3" accesskey="<?php if ( $user_ID ) echo '1'; else echo '4'; ?>"<?php if ( get_option('mim_mobile_xhtml') == 3 ) echo ' inputmode="user predictOn" '; ?>></textarea></p>
		<div class="fp"><input id="submit" name="submit" type="submit" value="<?php _e( 'Post' , 'mim' ) ?>" accesskey="<?php if ( $user_ID ) echo '2'; else echo '5'; ?>" class="button" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /><?php do_action( 'comment_form' , $post->ID ) ?></div>
	</form>
<?php endif; endif; ?>